
import request from '@/utils/axios';
const api_name = '/user';

export default {
    // 用户登录
    login(userInfo) {
        return request({
            url: `${api_name}/login`,
            method: 'post',
            data: userInfo
        });
    },
    // 头像上传
    // 用户注册
    avatarUpload(file) {
        const formData = new FormData();
        formData.append('file', file);
        return request({
            url: `${api_name}/avatarUpload`,
            method: 'post',
            data: formData,
            headers: { 'Content-Type': undefined } // 显式设置 Content-Type

        });
    },
    // 用户注册
    register(userInfo, avatarFile) {
        const formData = new FormData();

        // 将 userInfo 转换为 Blob 并指定 JSON 类型
        const userBlob = new Blob([JSON.stringify(userInfo)], {
            type: 'application/json'
        });
        formData.append('user', userBlob);
        formData.append('file', avatarFile);

        return request({
            url: `${api_name}/register`,
            method: 'post',
            data: formData,
            headers: { 'Content-Type': undefined } // 显式设置 Content-Type
        });
    },
    // 验证邮箱
    // 忘记密码
    verifyEmail(email) {
        return request({
            url: `${api_name}/verifyEmail`,
            method: 'post',
            params: { email } // 使用 params 发送简单参数
        });
    },
    forgetPassword(userInfo) {
        return request({
            url: `${api_name}/updatePassword`,
            method: 'put',
            data: userInfo
        });
    },
};
